from appium import webdriver
from app_wechat_po.base.base_page import BasePage


# Android 包名和页面名，获取命令：
# mac/linux: adb logcat ActivityManager:I | grep "cmp"
# windows: adb logcat ActivityManager:I | findstr "cmp"
class WechatApp(BasePage):
    implicitly_wait_time = 30
    def start(self):
        # 启动app
        if self.driver == None:
            print("driver == None")
            caps = {}
            caps["platformName"] = "Android"
            caps["platformVersion"] = "7.1.2"
            caps["deviceName"] = "attached-5554"
            caps["appPackage"] = "com.tencent.wework"
            caps["appActivity"] = ".launch.LaunchSplashActivity"
            caps["noReset"] = "true"
            # 动态页面等待0秒 再去查找元素， 默认是等待10秒
            caps["settings[waitForIdleTimeout]"] = 0
            self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
            self.set_implicitly(self.implicitly_wait_time)
        else:
            # 直接启动APP
            print("复用driver")
            self.driver.launch_app()
        return self

    def restart(self):
        self.driver.close()

    def stop(self):
        self.driver.quit()

    # 切换到配置中完成po操作
    def goto_main(self):

        from app_wechat_po.page.main_page import MainPage
        return MainPage(self.driver)